<template>
  <YvideoSlide
    video-height="100vh"
    :data="videoData"
    :videoIndex.sync="currentIndex"
    @refresh="refresh"
    @loadMore="loadMore"
    @share="share"
    @fabulous="fabulous"
    @follow="follow"
    @commentFabulous="commentFabulous"
    v-if="videoData"
  />
</template>

<script>
import YvideoSlide from '@/components/y-video-slide/y-video-slide'
import { articleGet, articleComment, delArticleComment } from '@/api/yuedu'
import headImg from '@/static/ucenter/head.png'
export default {
  components: {
    YvideoSlide
  },
  data() {
    return {
      videoData: null,
      currentIndex: 0
    }
  },
  computed: {
    userInfo() {
      return this.$store.getters.userInfo
    },
    isLogin() {
      return this.$store.getters.token
    }
  },
  onLoad({ id }) {
    this.getData(id)
  },
  methods: {
    getData(id) {
      articleGet(id).then((res) => {
        if (res.code === 200) {
          const data = res.data
          const result = [
            {
              id: '1',
              articleId: data.articleId,
              isFollow: 0,
              isFabulous: data.upvote ? 1 : 0,
              userNick: data.userName,
              videoContent: data.articleTitle || '',
              fabulousCount: data.upvoteCount || 0,
              commentCount: data.commentCounts || 0,
              shareCount: 499,
              videoUrl: data.articleAttaUrl,
              posterUrl: '',
              userHead: data.avatarUrl || headImg,
              commentObj: {
                count: data.commentCounts,
                list: data.comments ? data.comments.map(g => {
                  return {
                    userHead: g.avatarUrl || headImg,
                    userNick: g.userName,
                    content: g.commentContent,
                    time: g.createTime,
                    fabulousCount: 3737,
                    isFabulous: 1
                  }
                }) : []
              }
            }
          ]
          this.videoData = result
        }
      })
    },
    refresh() {},
    loadMore() {},
    share() {},
    fabulous(data) {
      if (!this.isLogin) {
        uni.showToast({
          title: '请先注册',
          mask: true,
          duration: 2000
        });
        setTimeout(() => {
          uni.navigateTo({
            url: '/pagesSub/userCenter/register'
          })
        }, 2000)
        return
      }
      if (!data.isFabulous) {
        articleComment({
          commentType: '1',
          articleId: data.articleId,
          userId: this.$store.getters.userInfo.userId
        })
      } else {
        delArticleComment({
          commentType: '1',
          articleId: data.articleId,
          userId: this.$store.getters.userInfo.userId
        })
      }
    },
    follow() {},
    commentFabulous() {
      
    }
  }
}
</script>

<style lang="less" scoped></style>
